package com.haiheng.pullup;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import androidx.annotation.NonNull;


/**
 * 作者：罗发新
 * 时间：2020/7/21  20:37
 * 邮件：424533553@qq.com
 * 说明：自启开关
 *
 * @author 罗发新
 */
public class MyBootReceiver extends BroadcastReceiver {
    String data = "com.haiheng.myapptest.ceshi.savelive";

    @SuppressLint("UnsafeProtectedBroadcastReceiver")
    @Override
    public void onReceive(@NonNull Context context, @NonNull Intent intent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            onBootCompleted(context, intent);
        } else if (Intent.ACTION_REBOOT.equals(intent.getAction())) {
            onReBoot(context, intent);
        } else if (data.equals(intent.getAction())) {
//            MyApplication.currentTime = System.currentTimeMillis();
//            Log.i("1111111111111", "守护时间==" + MyApplication.currentTime);
        }
    }

    /**
     * 设备重启
     */
    protected void onReBoot(@NonNull Context context, @NonNull Intent intent) {

    }

    /**
     * 在系统完成启动后广播一次
     */
    public void onBootCompleted(@NonNull Context context, @NonNull Intent intent) {

        // 要启动的Activity
        Intent mBootIntent = new Intent(context, MainActivity.class);
        mBootIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(mBootIntent);
    }
}
